
package org.apache.cassandra.cql.jdbc;

import java.lang.reflect.Field;
import java.sql.SQLException;
import java.util.Properties;

import org.apache.cassandra.thrift.Cassandra;
import org.apache.thrift.transport.TTransport;


public class LaUDCassandraConnection extends CassandraConnection {

	TTransport transport;
	public LaUDCassandraConnection(Properties props,Cassandra.Client cassandraClient,TTransport cassandraTransport) throws SQLException {
		//we do not want to this class execute super.consturctor...
		//so, we then close the client socket and replace it as laud socket.
		super(props);
		this.transport=cassandraTransport;
		super.close();			
			try {
				@SuppressWarnings("rawtypes")
				Class class1=this.getClass().getSuperclass();
				Field client=class1.getDeclaredField("client");
				client.setAccessible(true);
				client.set(this, cassandraClient);
				client.setAccessible(false);
				
				Field transport=class1.getDeclaredField("transport");
				transport.setAccessible(true);
				//transport.set(this, cassandraTransport);
				//we set transport null so that we make the transport.close() failed.
				transport.set(this, null);
				transport.setAccessible(false);
			} catch (SecurityException e) {
				e.printStackTrace();
				throw new SQLException("init cassandraConnection failed.");
			} catch (NoSuchFieldException e) {
				e.printStackTrace();
				throw new SQLException("init cassandraConnection failed.");
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
				throw new SQLException("init cassandraConnection failed.");
			} catch (IllegalAccessException e) {
				e.printStackTrace();
				throw new SQLException("init cassandraConnection failed.");
			}
	}
	public boolean  isConnected(){
		return this.transport.isOpen();
	}
	@Override
	public synchronized void close() throws SQLException {
		System.out.println("nothing");
	}
	
}